<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('支付通道列表')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: switch-css" />

</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>通道类型：</label>
                                <select name="type"  class="form-control" th:with="type=${@dict.getType('channel_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>通道编码：</label>
                                <input type="text" name="channel"/>
                            </li>
                            <li>
                                <label>通道描述：</label>
                                <input type="text" name="channelDesc"/>
                            </li>
                            <li>
                                <label>需要在线：</label>
                                <select name="needOnLine"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>需要产码：</label>
                                <select name="needGenQrcode"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>

                            <li>
                                <label>是否禁用：</label>

                                <select name="disabled"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否浮动：</label>
                                <select name="fd100"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>地区分控：</label>

                                <select name="isArea"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>固定金额：</label>
                                <select name="isRegularAmount"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>

                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:channel:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="business:channel:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:channel:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:channel:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
     <th:block th:include="include :: switch-js" />

     <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('business:channel:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:channel:remove')}]];
        var prefix = ctx + "business/channel";
        var typedata = [[${@dict.getType('channel_type')}]];
        var ysdata = [[${@dict.getType('yes_or_no')}]];
        var reslogindata = [[${@dict.getType('rec_login_type')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "支付通道",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'type',
                    title: '通道类型',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(typedata, item.type);
                    }
                },
                {
                    field: 'channel',
                    title: '通道编码'
                },
                {
                    field: 'channelDesc',
                    title: '通道描述'
                },
                {
                    field: 'needOnLine',
                    title: '是否需要在线',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(ysdata, item.needOnLine);
                    }
                },
                {
                    field: 'needGenQrcode',
                    title: '是否需要生成二维码',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(ysdata, item.needGenQrcode);
                    }
                },
                {
                    visible: [[${isShow}]],
                    field: 'disabled',
                    title: '通道状态',
                    // formatter: function(value, item, index) {
                    //     return $.table.selectDictLabel(ysdata, item.disabled);
                    // }
                    formatter: function (value, row, index) {
                        let swState = row.disabled == 0 ? true : false;
                        return '<input type="checkbox" name="isDisabled" '+(swState ? "checked" : "")+' value="'+row.id+'"/>';
                    }
                },
                {
                    field: 'fd100',
                    title: '是否浮动',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(ysdata, item.fd100);
                    }
                },
                {
                    field: 'limitPerMinMoney',
                    title: '单笔最小限额',
                    formatter: function (value, row, index) {
                        return (row.limitPerMinMoney == null ? '-' : row.limitPerMinMoney/100 + '元')
                    }
                },
                {
                    field: 'limitPerMaxMoney',
                    title: '单笔最大限额',
                    formatter: function (value, row, index) {
                        return (row.limitPerMaxMoney == null ? '-' : row.limitPerMaxMoney/100 + '元')
                    }
                },
                {
                    field: 'loginType',
                    title: '账号登录类型',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(reslogindata, item.loginType);
                    }
                },
                {
                    field: 'isArea',
                    title: '是否地区分控',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(ysdata, item.isArea);
                    }
                },
                {
                    field: 'isRegularAmount',
                    title: '是否固定金额',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(ysdata, item.isRegularAmount);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="openRecipInfo(\'' + row.id + '\')"><i class="fa fa-edit"></i>子账号</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="weightSet(\'' + row.id + '\')"><i class="fa fa-edit"></i>下游商户</a> ');

                        return actions.join('');
                    }
                }],
                onLoadSuccess: function(){
                    //
                    $("[name='isDisabled']").bootstrapSwitch({
                        onText: '启用',
                        offText: '禁用',
                        size : 'small'
                    }).on('switchChange.bootstrapSwitch', function (event, state){
                        //修改操作
                        $.operate.post(prefix + "/changeChannelDisabledStatus", { "id": event.currentTarget.value, "disabled": state ? 0 : 1 });
                    });

                }
            };
            $.table.init(options);
        });
        function weightSet(id) {
            $.modal.openTab("权重设置", prefix + "/weightSet/"+id);
        }
        function openRecipInfo(id) {

            var url =ctx + "business/recipientInfo/add";
            $.modal.openTab("新增收款账号", url);
        }
        function disablestatusTools(row) {
            if (row.disabled == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="channelenable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="channeldisable(\'' + row.id + '\')"></i> ';
            }
        }
        function channelenable(userId) {
            $.operate.post(prefix + "/changeChannelDisabledStatus", { "id": userId, "disabled": 0 });
        }

        /* 用户管理启用 */
        function channeldisable(userId) {
            $.operate.post(prefix + "/changeChannelDisabledStatus", { "id": userId, "disabled": 1 });
        }

    </script>
</body>
</html>